<template>
  <!-- 页面-新建配置参数-选择值集弹框 -->
  <div style="height:300px" class="selectCompany-page">
    <!-- 搜索区域 -->
    <SelfAdaption>
      <Form
        :model="searchForm"
        ref="searchForm"
        slot="adaption-bar"
        label-position="top"
        class="ivu-form-no-margin-bottom"
        inline
      >
        <!-- 值集编码 -->
        <Form-item prop="VSCode" :label="$t('module.valueSet.vsCode')">
          <Input
            type="text"
            :maxlength="50"
            v-model.trim="searchForm.vsCode"
            :placeholder="$t('module.valueSet.enterVsCode')"
            @on-enter="search"
          ></Input>
        </Form-item>
        <!-- 值集名称 -->
        <Form-item prop="vsName" :label="$t('module.valueSet.vsName')">
          <Input
            type="text"
            :maxlength="50"
            v-model.trim="searchForm.vsName"
            :placeholder="$t('module.valueSet.enterVsName')"
            @on-enter="search"
          ></Input>
        </Form-item>

        <!-- 查询\重置按钮 -->
        <Form-item prop="button" class="search-solt-btn">
          <RPButton optType="search" @click="search" />
          <RPButton optType="reset" @click="reset" />
        </Form-item>
      </Form>
    </SelfAdaption>
    <InnerPageTable ref="relectVSTable" :config="pageTableConfig">
      <!-- handler bar 查询/重置-->
      <!--
      <div slot="handle-bar">
        <RPButton optType="search" @click="search" />
        <RPButton optType="reset" @click="reset" />
      </div>
      -->
    </InnerPageTable>
  </div>
</template>
<script>
// import { getCompanyList } from "@/api/orgApi.js";
import locales from "./locales.js";

export default {
  components: {},
  props: {},
  name: "selectValueSet",
  mixins: [locales],
  props: {
    // productId: {
    //   type: String,
    //   default: ""
    // },
    // tenantCode: {
    //   type: String,
    //   default: ""
    // }
    paramInfo: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      treeTypeList: {},
      productList: {},
      tenantList: {},
      searchForm: {
        // // productCode: "",
        // tenantCode: this.tenantCode,
        enabled: 1, //enabled:null或不传enabled字段显示所有数据。为1时为有效数据，0为无效数据。（只要显示有效数据）
        vsCode: "", // 公司编码
        vsName: "" // 公司名称
      },
      pageTableConfig: {
        action: null,
        resource: null, //default
        customDataProcess: null, //default
        loadDataFn: this.GetValueSetList,
        columnsFn: this.generateColumns,
        autoFirst: false, //default false
        highlightRow: true,
        rowClickHandle: this.getRowData
      }
    };
  },
  computed: {},
  created: function() {
    this.$emit("SetTitle", this.$t("module.configManage.seleectValueSet"));
    this.$emit("SetPageWidth", 866);
    // this.$emit("SetPageActions", [
    //   {
    //     text: this.$t("module.orgManage.confirm"),
    //     theme: "primary",
    //     handle: this.confirm
    //   },
    //   {
    //     text: this.$t("common.close"),
    //     theme: "primary",
    //     handle: () => {
    //       this.$emit("Close");
    //     }
    //   }
    // ]);
    this.init();
  },
  beforeMount: function() {},
  mounted: function() {
    this.search(1);
  },
  beforeDestroy: function() {},
  destroyed: function() {},
  methods: {
    // 获取值集列表
    GetValueSetList({ responseProcess, param }) {
      $http.post(`${window.RPConfig.setting}/valueset/list/page`, param).then(response => {
        responseProcess(response.data);
      });
    },
    // 点击当前行触发
    getRowData() {
      const paramInfo = this.paramInfo;
      if (paramInfo.id && paramInfo.valueSetId) {
        this.$confirm
          .warning(this.$t("module.configManage.valueSourceWarning"))
          .then(() => {
            let row = this.$refs["relectVSTable"].getHighlightRow();
            this.$emit("Close", row);
          })
          .catch(_ => _);
      } else {
        let row = this.$refs["relectVSTable"].getHighlightRow();
        this.$emit("Close", row);
      }
    },
    init() {},

    // 查询
    search(page) {
      this.$refs["relectVSTable"].load(this.searchForm, page);
    },
    // 重置
    reset() {
      // this.$refs["searchForm"].resetFields();
      this.searchForm.vsCode = "";
      this.searchForm.vsName = "";
      this.search(1);
    },
    // 表格数据
    // loadData({ responseProcess, param }) {
    //   return window.$http
    //     .post(`${window.RPConfig.mgt}/tree/list/page`, param)
    //     .then(response => response.data)
    //     .then(res => responseProcess(res));
    // },
    // 表格的列
    generateColumns() {
      return [
        {
          title: this.$t("module.valueSet.vsCode"),
          key: "vsCode",
          align: "left"
        },
        {
          title: this.$t("module.valueSet.vsName"),
          key: "vsName",
          align: "left"
        }
      ];
    },
    // 确定
    confirm() {
      // let row = this.$refs["relectVSTable"].getHighlightRow();
      // this.$emit("Close", row);
    }
  },
  watch: {},
  directives: {}
};
</script>
<style lang="less">
.selectCompany-page {
  .inner-table {
    .single-table-con {
      padding-top: 0;
      .table-bar {
        display: none;
      }
      div:nth-child(3) {
        overflow: inherit !important;
      }
    }
  }
}
</style>
